//
//  ICigarette.m
//  XRmenu
//
//  Created by yangxh on 11-3-24.
//  Copyright 2011 E0571. All rights reserved.
//

#import "ICigarette.h"


@implementation ICigarette

@synthesize cigaretteId;
@synthesize CO;
@synthesize Id;
@synthesize name;
@synthesize nicotine;
@synthesize package;
@synthesize specification;
@synthesize tar;
@synthesize spellCode;

//=========================================================== 
// - (id)init
//
//=========================================================== 
- (id)init
{
    return [self initWithCigaretteId:nil CO:nil Id:0 name:nil nicotine:nil package:nil specification:nil tar:nil];
}


//=========================================================== 
// - (id)initWith:
//
//=========================================================== 
- (id)initWithCigaretteId:(NSString*)aCigaretteId CO:(NSString*)aCO Id:(NSInteger)anId name:(NSString*)aName nicotine:(NSString*)aNicotine package:(NSString*)aPackage specification:(NSString*)aSpecification tar:(NSString*)aTar 
{
    self = [super init];
    if (self) {
        self.cigaretteId = aCigaretteId;
        self.CO = aCO;
        self.Id = anId;
        self.name = aName;
        self.nicotine = aNicotine;
        self.package = aPackage;
        self.specification = aSpecification;
        self.tar = aTar;
    }
    return self;
}


//=========================================================== 
// + (id)objectWith:
//
//=========================================================== 
+ (id)objectWithCigaretteId:(NSString*)aCigaretteId CO:(NSString*)aCO Id:(NSInteger)anId name:(NSString*)aName nicotine:(NSString*)aNicotine package:(NSString*)aPackage specification:(NSString*)aSpecification tar:(NSString*)aTar  
{
    id result = [[[self class] alloc] initWithCigaretteId:aCigaretteId CO:aCO Id:anId name:aName nicotine:aNicotine package:aPackage specification:aSpecification tar:aTar];
	
    return [result autorelease];
}

//=========================================================== 
// - (NSArray *)keyPaths
//
//=========================================================== 
- (NSArray *)keyPaths
{
    NSArray *result = [NSArray arrayWithObjects:
					   @"cigaretteId",
					   @"CO",
					   @"Id",
					   @"name",
					   @"nicotine",
					   @"package",
					   @"specification",
					   @"tar",
					   @"spellCode",
					   nil];
	
    return result;
}


//=========================================================== 
// - (NSString *)descriptionForKeyPaths
//
//=========================================================== 
- (NSString *)descriptionForKeyPaths 
{
    NSMutableString *desc = [NSMutableString string];
    NSEnumerator *e = [[self keyPaths] objectEnumerator];
    NSString *thisKey;
    [desc appendString:@"\n\n"];
	
    while ((thisKey = [e nextObject])) {
        [desc appendFormat: @"%@: %@\n", thisKey, [self valueForKey:thisKey]];
    }
	
    return [NSString stringWithString:desc];
}

- (NSString *)description
{
	return [self descriptionForKeyPaths];
}

//=========================================================== 
// dealloc
//=========================================================== 
- (void)dealloc
{
    [cigaretteId release];
    cigaretteId = nil;
    [CO release];
    CO = nil;
    [name release];
    name = nil;
    [nicotine release];
    nicotine = nil;
    [package release];
    package = nil;
    [specification release];
    specification = nil;
    [tar release];
    tar = nil;
	[spellCode release];
	spellCode = nil;
	
    [super dealloc];
}

+ (ICigarette *)iCigaretteByParse:(NSDictionary *)info
{
	ICigarette *cig = [ICigarette objectWithCigaretteId:dictObject(info,@"CigaretteId")
													 CO:dictObject(info,@"CO")
													 Id:dictInt(info,@"ID")
												   name:dictObject(info,@"Name")
											   nicotine:dictObject(info,@"Nicotine")
												package:dictObject(info,@"Package")
										  specification:dictObject(info,@"Specification")
													tar:dictObject(info,@"Tar")];
	cig.spellCode = dictObject(info,@"SpellCode");
	return cig;
}

@end
